
const app = getApp().globalData

//import { sale_list } from '../../../api/index'
import { bbsList,getImages} from '../../../api/hot'
Page({
  data: {
    list: [],
    finished: false,
    page: 1,
    formMark: false,
    imageUrl:'',
    key: '',
  },
  keySearch(e) {
    this.data.finished = false
    this.data.page = 1
    this.getList()
  },
  clearKey(e) {
    this.setData({ key: '' })
  },
  onChange(e) {
    this.setData({ key: e.detail })
  },
  onLoad() {
    this.getImage()
    this.getList()
  },
  onShow() {
    // this.getImage()
    // this.getList()
  },
  gopage(e) {
    const { url } = e.currentTarget.dataset
    wx.navigateTo({ url })
  },
  getImage(){
    getImages().then((res) => {
      console.log(res.datas);
      this.setData({
        //formMark: true,
        imageUrl: res.datas
      })
    })
  },
  getList() {
    bbsList({page: this.data.page, limit: 20, k: this.data.key}).then(
      (res) => {
        console.log('===bbss===');
        console.log(res);
      wx.stopPullDownRefresh()
      this.setData({
        formMark: true,
        list: this.data.page > 1 ? this.data.list.concat(res.datas) : res.datas
      })
      if (this.data.list.length >= res.total) {
        this.data.finished = true
      }
    })
  },
  onPullDownRefresh() {
    this.data.finished = false
    this.data.page = 1
    this.getList()
  },
  onReachBottom() {
    if (this.data.finished) {
      return
    }
    this.data.page++
    this.getList()
  },
  gopage(e) {
    const { url } = e.currentTarget.dataset
    wx.navigateTo({ url })
  }
})